<?php
class lovewall
{
	var $db;
	var $pages;
	var $number;
	var $table;
    var $contentpages;

    function __construct()
    {
		global $db,$M;
		$this->db = &$db;
		$this->table = DB_PRE.'lovewall';
		$this->M = $M;
    }

	function lovewall()
	{
		$this->__construct();
	}

	function get($specialid)
	{
		$specialid = intval($specialid);
		if($specialid < 1) return false;
		return $this->db->get_one("SELECT * FROM $this->table WHERE specialid=$specialid");
	}

	function save($info, $where = "", $id = 0)
	{
		if($id > 0)
		{
			$result = $this->db->update($this->table, $info, $where);
		}
		else
		{
			$result = $this->db->insert($this->table, $info);
		}
		return $result;
	}

	function delete($id)
	{
		$id = intval($id);
		return $this->db->query("DELETE FROM $this->table WHERE id=$id");
	}

	function listinfo($where = '', $order = '', $page = 1, $pagesize = 50)
	{
		if($where) $where = " WHERE $where";
		if($order) $order = " ORDER BY $order";
		$page = max(intval($page), 1);
        $offset = $pagesize*($page-1);
        $limit = " LIMIT $offset, $pagesize";
		$r = $this->db->get_one("SELECT count(*) as number FROM $this->table $where");
        $number = $r['number'];

		
        $this->pages = pages($number, $page, $pagesize);
		
		$array = array();
		$result = $this->db->query("SELECT * FROM $this->table $where $order $limit");
		while($r = $this->db->fetch_array($result))
		{
			$array[] = $r;
		}
		$this->number = $this->db->num_rows($result);
        $this->db->free_result($result);
		return $array;
	}

	function getFiveVist($where = "")
	{
        if($where) $where = " WHERE $where";
		$r = $this->db->get_one("SELECT count(*) as number FROM $this->table  $where");
        $number = $r['number'];
		return $number;
	}

	function lockmessage($id, $lock = 0)
	{
       return $this->db->query("UPDATE `$this->table` SET  `Lock` = $lock WHERE id=$id");
	}
   
}
?>